Avoid printing incomplete Gcode: write to tmp file first, then rename atomically.