Close fd again after opening with mkstemp

Fixes #155

Effectiveness of this fix still needs testing.