Not sure how python behaves but here, you may be relying on the garbage collector to close the file. Buffering might lead to a corrupted firmware being flashed.