Fix descriptor leak in convert engine

Plus better approach for working with files
Using NamedTemporaryFile instead of mkstemp & open or os.fdopen
This make code cleaner and less error-prone.

Author:    Vitaly Olevinsky <olevinskyvs@gmail.com>
Tests for descriptor leaks
Merge pull request #213 #177 from seedinvest/flatten and olevinsky/fix_descriptor_leak