Your friend was absolutly right.
You can't have at the top:
print "Content-Type text/html\n";
It just won't work.
So delete that line.
After that it should work.
Mail me at firstname.lastname@example.org
with your url and the script if you need any more help.
I'll have a look at the script for you.