in reply to Create a html page on fly
In addition to what everybody's already said...
The above prints an HTTP header which has no business being in an HTML file on the filesystem. Ditch it.