Fix Python BOM script bug when output file cannot be opened. (fixes:lp:1391904)