Well this still isn't really enough information for me to help.
Ok I'll put it really simple, are you trying to create a file on the server from some data inputed through an html form? Or is this from a database, or from some other input?
Is it for use online or are you talking about using the commandline php exe to preprocess the pages?
There are so many combinations of this topic that again you have to specify what it is you are wanting to do.