Yep, find out what permission is on the folder.
ls -la foldername

Next try to give the folder write access to everyone
chmod 0777 foldername

Then run your script in apache again and see if it generates the file for output. If it does, you have a permission issue. If it doesn't, something else is going on and I'm not sure what.