StringIO.{writeLines,appendLine} do not properly close file handles when writing problems occur

Edited by Tuukka Lehtonen