Close fd after using it and before deleting it (refs #4075)