Make package work as library as well as from command line.

(I wasn't sure if this should be sent to @internetarchive or @rajbot -- let me know.)

This pull req. changes CDX-Writer so it can be imported from other Python packages, rather than assuming that it will run from the command line. (Writing to a file handle instead of calling print, throwing exceptions instead of calling sys.exit(), etc.)

It should still work from the command line as well, but I haven't tested that side of things.