Permissions for perl scripts/write

I have a perl scripts that uses a cgi script written in perl that executes and read from the same
file. The permissions are set to 777 (not a good practice but what can I do - I didn't write it)
but the minute the script runs, permissions are changed to 644 and the program dies. Now it
seems that it may be the fault of 'Apache - httpd' but I personally have never seem a script
like this before that wants to run and change file permission.
May be I should tell you the lay out:
cgi-bin/scripts -> runs and read file: directory/file.cgi ->then writes to this file -> which
changes permission so it will not run again. Program dies.
That it folks!!!
Is there a fix? Is the 'apache-httpd' not working correctly? I have other perl scripts that do run
correctly but none do this stuff (rewrite files that are executable).