Utility method to write string into a file