Best way to write to a file

Looking for the best way to do the following:

Want a button style item that when I double click it will write to a file with the sensor name and date.
So not sure if this is the simple way of doing it but I did the following:

  • Created a helper sensor called X
  • Added a Notify to my config.yaml file

    notify: 
      - name: X platform:
        platform: file
        filename: /config/notifications/X.csv 
        timestamp: False

  • Created a Button that calls on the Notify service above to write to file
show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: notify.X
  target: {}
  data:
    message: '{{ now().strftime(''%m/%d/%Y'') }}, Changed X'
theme: Fluent Blue
entity: Sensor.X
icon_height: 40px