I guess I'm not for sure on what you are wanting.
To dump an excel file to the user and have it open up on his box I use
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=mvog.xls");
echo $xls;
To just create/update a file and store it
$logfile="hits.cnt";
$count = trim(file_get_contents($logfile)) or $count = 0;
/* Increase the count by 1 */
$count = $count + 1;
$fp = @fopen($logfile,'w+');
flock($fp, LOCK_EX);
fputs($fp, $count);
flock($fp, LOCK_UN);
fclose($fp);