in reply to Premature end of script header error

Are the line endings correct? The shebang line pointing to the right place? Have you tried adding
use CGI::Carp qw( fatalsToBrowser );
to the top of the script?

What happens if you comment out the

open... print... close...
lines?

You'll have at least eliminated a few possiblilites!

Hope this helps.

Update

This will help. It mentions checking the scripts permissions (which I forgot).