Sure. fwrite needs to use a file descriptor (a pointer to the file) to be able to work ok.
Lets's see an example:
$fd = fopen("fLIPIS.666","w");
fwrite($fd,"fLIPIS is a total sucker\n");
fwrite($fd,"but i like his style...\n");
fclose($fd);
<B>First line:</B> We use fopen to open this new file. The pointer to the file is stored on $fd.
<B>Second and third lines:</B> Using fwrite, we write some senseless things to the file. See that i use $fd to tell fwrite wich one is the pointer to the file.
<B>Fourth line:</B> We close the file (EXTREMELY IMPORTANT)
Now, if the code above is understood, you shouldn't have trouble with yours. Anyway, take a look here if you have more doubts:
http://www.php.net/manual/en/ref.filesystem.php
Hope it helps you
fLIPIS