Fixed small bug writing output file