Fixes an issue where the output was opened to write