Add output file parameter, robuster exception handling

Signed-off-by: Dan Scott <dan@coffeecode.net>