It seems my python script will stop running once it reach this write file section, the other write file section works fine but only this part has this problem.