[IMPROV] Use codecs.open()

Instead of open the temporary file in binary mode it uses codecs.open to
decode and encode automatically.

Change-Id: If586791174d273d26e33cb1a342f6f27319822ee