in reply to cache problems

I think there is a \n too many here:
print "Content-type: text/html\n\n";
what you print with the next:
print $header;
will become part of the body that you're sending out. Is that intentional?

Liz