Fix small bug: don't write newlines when errors occur