Oops, sorry about the typos. I guess I didn't realize that about STDERR, I'll take that part out. (I'm actually updating someone else's code here, but that doesn't absolve me of not cleaning it up properly).
As for the \n\n after the Content-type header, why is that an error? It prints correctly. I didn't put them there specifically, but I think the original author did that to ensure that the HTTP Header was definitely "done" before starting (but I could remove it).