I don't know anything about Perl, but "Content-type: text/html\n\n" looks a lot like a header, which should be send before any output (and I beleive this isn't right in this script, since you use print to send a header (?) and also your output.)
Also, HTML headers have to be separated by "\r\n", not by "\n\n".