finish implementation of '-o <file>' option to write output to a file