Add option for writing the output to stdout or file.