when posting Code Contributions please use a more descriptive description then just cutting and pasting the title of your post ... what does your code do? why might people want to use it? how would people go about using it if they wanted to?
to be frank: your code doesn't seem that useful beyond a single use case -- the only input it takes in is a directory name to write a file whose name is hardcoded, and all of the data that will be written to that file is hardcoded ... the mount of time necessary for someone to customize your script to be useful for them seems like it would be approximately the same amount of time as if they wrote their own script.
your first few error messages don't distinguish themselves ... they give no indication of what the problem was with the file.
you don't need to use "system('rm')" to delete a file, that's what unlink is for.