Third argument is optional, but if set to ab it will not overwrite the whole file, instead it will add the contents to the end.
There is no need to build the entire path to the file manually, if the directory does not exist when writing to the file, it will be created automatically.