The only thing that comes in mind since you can execute your script from /var/www/cgi-bin is that you use suexec. Check with
Code:
/path/to/apache/bin/apachectl -V
or take a look at the logs when you restart apache to see if that's the case. Then you can either
disable it, or read the whole document of the previous link in order to configure it correctly