You're getting the "Server Error" because you're not printing out headers in your 'diedebug' statement. A quick fix would be to:
- Change your require 'cgi.pm' to a use CGI qw(:standard :cgi-lib)
- Add a print header() to the top of your diedebug routine.
I'd also look at CGI::Carp.