I probably don't know enough about the problem your having, but I'll give it a shot anyway...
So you run it from command line and it runs OK? And have a #!path/to/interpreter in the script? Yeah, sounds reasonable, but only for command line use.
When called thru the web server, the file must not have the hashbang (#!) and interpreter in the beginning, and must not have the exec tag set.
-jani