I agree with Joseph that TeX doesn't support appending to an existing file. However it is possible to read the existing content and write it together with the new content back to the file. This is of course much less efficient than simply appending content, but the only possible way in TeX.
The catchfile
makes the reading of the existing content quite easy:
\documentclass{article}
\usepackage{catchfile}
\newwrite\appendwrite
\newcommand*\appendtofile[2]{%
\begingroup
\IfFileExists{#1}%
{\CatchFileDef{\filecontent}{#1}{\endlinechar=`^^J\catcode\endlinechar=12\relax}}% keep existing end-of-lines
{\let\filecontent\empty}%
\immediate\openout\appendwrite=#1\relax
\immediate\write\appendwrite{\filecontent #2}%
\immediate\closeout\appendwrite
\endgroup
}
\begin{document}
\appendtofile{\jobname.test}{First line}
First:\\\fbox{\input{\jobname.test}}
\appendtofile{\jobname.test}{Second line}
Second:\\\fbox{\input{\jobname.test}}
\end{document}
See also the answers to the question "File copy without expansion".
\openout
primitive simply does not allow appending. (Of course, LuaTeX is a different case).