Add support for writing output to a file rather than stdout