I guess I must not understand the question. What is wrong with:
\newcommand{\mywrite}[1]{\immediate\write\myoutputfile{#1}}
Although I like to be a bit more complete and handle the fact that not all input files may be read on each compilation (due to \includeonly) but you still want the complete lesson plan even if some parts live in the non-included files, also the user maybe want to switch off all file output via \nofiles, or only wants to stop automatically updating the lesson plan so they can do some hand editing (here remove the \makemyrecords line). I would also want to avoid putting spurious spaces in the document, so I would do it this way, modelled loosely after how \makeindex works in latex:
\ProvidesPackage{myrecords}%
[2010/08/14 v0.01 my example record package (LSB)]
\NeedsTeXFormat{LaTeX2e}
\def\myrec@outputfileextension{.mrc}
\newcommand*{\myrec@write}[1]{}
\def\myrec@verb{\expandafter\strip@prefix\meaning}
\newcommand*{\makemyrecords}{%
\newwrite\myrec@outfile
\immediate\openout\myrec@outfile=\jobname\myrec@outputfileextension
\typeout{Writing my records to file \jobname\myrec@outputfileextension}%
\let\makemyrecords\@empty
\renewcommand*{\myrec@write}[1]{\immediate\write\myrec@outfile{##1}}%
}
\@onlypreamble\makemyrecords
\newcommand*{\myrecord}[1]{%
\@bsphack
\if@filesw
\immediate\write\@auxout{\string\myrecordentry{#1}}%
\fi
\@esphack
}
\newcommand*{\myliteral}[1]{%
\@bsphack
\if@filesw
\def\@tempa{#1}
\immediate\write\@auxout{%
\string\myrecordentry{%
\myrec@verb\@tempa}}%
\fi
\@esphack
}
\newcommand*{\mywritecurrenttitle}{
\if@filesw
\immediate\write\@auxout{\string\myrecordentry{%
\string\lessonplanitem{\currenttitle}}}%
\fi
}
\newcommand*{\myrecordentry}[1]{}
\AtEndDocument{%
\renewcommand*{\myrecordentry}[1]{%
\def\@tempa{#1}%
\myrec@write{\myrec@verb\@tempa}%
}}
\endinput
If I test this with what I imagine you have in mind (obviously you would want to wrap the \renewcommand{\currenttitle}\mywritecurrenttitle up with a command that generates the document sectioning, or put them in hooks provided by your document class).
\documentclass{article}
\usepackage{myrecords}
\makemyrecords
\begin{document}
\myliteral{
\documentclass{lessonplan}
\begin{document}}
\newcommand*{\currenttitle}{This is the title of lesson 1}
\mywritecurrenttitle
Lesson 1....
\renewcommand{\currenttitle}{This is the title of lesson 2}
\mywritecurrenttitle
Lesson 2.....
\myliteral{\end{document}}
\end{document}
Then, as expected, the lesson plan file looks like
\documentclass {lessonplan} \begin {document}
\lessonplanitem {This is the title of lesson 1}
\lessonplanitem {This is the title of lesson 2}
\end {document}