Maybe you're printing the file before your header:
# (Your print stuff)
open (FILE, "..."); # ...
my ($cgi) = new CGI;
print $cgi->header;
In this case, the CGI will not output a valid header, instead
showing the contents of your file. An invalid header is grounds
for a 500 error.
Note that if you run your script on the command line, it
will "work" fine, in as much as it runs, but it will not
output the proper header for your Web server.
For debugging this kind of thing, you absolutely
must
use
CGI::Carp. It's not optional. It will log
all errors to your error_log instead of them being lost in
the great void.