make sure the tmp file is closed before moving

Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
Merge pull request #137 from alfredodeza/6701-2

make sure the tmp file is closed before moving