When writing state make sure to create the dir if it doesn't exist