in reply to Debugging without shell access?
Your script doesn't send a Content-type header, which is what the part of the error message that says "Premature end of script headers" is referring to. Try adding the following line just above where you print out that block of HTML:
print "Content-Type: text/html\015\012";