An option could be to create alarms and run a script which writes to the text file once the alarm is triggered.
see e.g. http://www.vkernel.ro/blog/configuring-vmware-vcenter-server-alarms for a sample of how to configure a VM state "Power Off" alarm.
André