write output manually (to avoid file locks on Windows)