Add utility method writeToString