Changed all file stream write to output stream or error stream writes, as appropriate.