Write output to a string instead of directly to STDOUT

This way the caller can decide to write to stdout or file, etc.