Is this all that your script contains? My first guess would be that you may have excluded some code before this, and that code is throwing out some sort of warning, which is messing up the headers. Everything that you posted looks correct and
print "Content-type: text/html\n\n"; should be all the headers that you need.
If there is anymore info that you could give, I could probably give you a better answer.