if you are tring to put a php file in why not use an include()?
I generally use file() to get the contents of a file, then if I want to write to it, I do that seperately by fopen($filename, "w+") ing it then using fwrite() to put contents in. Note, when I do this I use file() to read the contents first, then add what I want this, before fopen()ing it, and re-writing the entire file. (w+ option truncates the file to zero length).
This is the typical code I use to do such a thing:
$filecontents = file('myfile');
$filestuff = $filecontents[0]; //all my stuff is stored on the first line of files
$stufftoadd = "add this text";
$writeline = $filestuff.$stufftoadd;
$fo = fopen("myfile", "w+");
fwrite($fo, $writeline);
fclose($fo);
I expect there is an better way to do this, but this is the way I do it. The code could probably be compacted a little as well. Obviously you can do different things to the $writeline before you write it, you don't have to just add stuff to the end of it.
HTH
Harry