Add docs and minor tweaks:

Stripped trailing whitespace. Removed one unnecessary list
comprehension. Made outfile optional arg, defaults to stdout.