Check for OSError in try_write instead of IOError