fix writing of files if output argument passed