Here is part of a script that i use to open up a log file and append some info to it.
// write hit data
$file = fopen( "d:\absolute_path_here\stats\validate.txt", "r+" );
fseek( $file, filesize( ""d:\absolute_path_here\stats\validate.txt" ) );
$write_data = "\nHit Made at: " . date( "H:i:s d/m/Y" ) . " \t RefNum: " . $RefNum . " \t Amount: " . $Amount . " \t Response: " . $response;
fwrite( $file, $write_data );
fclose( $file );
You will find with accessing files you can either has the absolute path like this one or use unix style relative paths. In this case i could have used:
$file = fopen( "./stats/validate.txt", "r+" );
As to the permissions, when writing to a file in windows, the internet guest user needs write access to the directory that contains the file as well as the file iteself.
I find the best way to do this is to create a directory just for the file and give the IUSR_SERVERNAME user full access to this new folder and all its subdirectories.