If there isn't a usefull error in your webserver log then the problem is probably not printing your document header (
use CGI; my $cgi = new CGI; print $cgi->header;) before printing the error result...
That's just a guess. I'm not sure the relevent code is show.