add option to write output into a file

implement #3