Temporarily redirect write/1 or current_output to a file

A post was split to a new topic: Unexpected result using with_output_to and string(S)