in reply to writting new files in perl
If the script is in your own home directory, make sure 'other' write permissions are set so that the webserver user (usually nobody) can create files there. Try chmod o+w directory
If that doesn't work, follow target's advice!