The HTML::Stream perl module provides you with an object-oriented (and subclassable) way of outputting HTML. Basically, you open up a "stream" on an existing filehandle and do all of your output with method invocations: the module takes care of all the HTML-escaping of text and attribute values. You can even intermix HTML-stream-output and ordinary-print-output.
HTML::Stream is now being maintained by Daniel T. Staal. We pass our software on to others when we feel they can do a better job maintaining and extending it than we can — it keeps good code from becoming obsolete.