I think it's:
$fileName = "whatever";
$theFile = fopen ($fileName, "a+")
or die("Unable to open file($fileName)");
fwrite($theFile, "Your data here \n");
fclose($theFile);
NB the a+ opens the file for reading and writing, placing the pointer at the end of the file, so any dtaa written to it will be appended at the end.