Yep, hit www.php.net and look at the fwrite(), fopen() functions. Theese will do everything you need to do. It will be a case of telling it to write to a file but if the file does not exist then create it.
Remember to chmod any text file to give it the correct permissions otherwise reading and writing to it wont happen.