in reply to Premature end of script headers (i know, i know...)
You can print "Content-type: text/html\n\n"; first and then do your file printing and html outputting. That should work.
Perhaps something is trying to write to STDERR before you do the show_html which causes the premature... error