Add `--output-file` flag for writing values to file
This is a further development on @christf's #3367 (feat: allow writing to output file), which handles some edge cases not considered.
Other uses of stdout, such as tests, fuzzers, disassembly, and debug traces, remain directed to stdout; only JSON values are written to the output file. Consequently, users of --debug-dump-disasm and --debug-trace can now separate the debug and JSON outputs. On Windows, the output file is marked as binary when --binary is passed.
This incorporates the commit from #3367, but with minor fixes squashed in.
Fixes #2418 Closes #3367
Well that was a lot of back and forth with CI to identify the problem with Windows :sweat_smile:. I'm confident in this now.