Make GDAL use Python exceptions
Switch from tempfile.mktemp to NamedTemporaryFile

tempfile.mktemp is unsafe and depricated.
Instead, use NamedTemporaryFile to create file object and just
retrieve the file name from it. Overwrite file object created using
GDAL. NamedTemporaryFile with delete=True will ensure the file is deleted
after we exit. By default, save tempfile in os.getcwd()
Update to Python 3 print function