Export sensor data to text file

I use shell_command in an automation to rename my text files monthly. I imagine you could use the same process to delete the file before writing a new one.