First, you have to read the content of the file to a variable, then write the new entry to the file, then the old content...
$fp = fopen("file.txt","w+");
$cont = fread($fp, filesize("file.txt"));
fwrite($fp, $new_entry);
fwrite($fp, $cont);
fclose($fp);
/Staffan