OSL EventBoolFlag/Write text file

I use Open Shading Language. I need save event (if (speed_particle > 0.5) {boolean_flag = 1}).
The trouble is that the variable “flag” is reset every frame!
How can i save the value of the variable “flag”? Or How can i save the value of the variable in the file? (How can i write file using the Open Shading Language?)