My mistake - you are quite right. I had missed the print qq($doctypeAndHeader); line. You don't need to quote a single variable when you print it like that, BTW. print $doctypeAndHeader; will do just as well and might be less confusing.
So, you should be seeing this on each call. If not, check the webserver error log for the reasons. Good luck!