Fixed writeToFile to work with shapes