Fixes for python3

- Output file must be opened binary mode for ET.
- There is no basestring class in python3.