revert to using codecs.open() for output files instead of io.open() as the latter cannot write str objects in text mode under Py2 (and we erroneously do that in some spots)