I'm creating a file in CGI (Perl), but after it's created via the script, I can't replace it or chmod it.

What's the correct way to create a file in perl?