Hi,
You can store all the generated output in a variable. (So, instead of using a echo or printf statement every time output is generated, you do something like:
$output .= "your output";
This output you can then, at the end of your scripts write to a file and echo to the screen (So the user gets'to see what was saved).
If you save as HTML file, consider using cascading stylesheets (CSS) for formatting.
J.