My use case needs to store the data on a disk immediately when the data is available. I'm using Raspberry PI and few lasers. Once the laser is activated/deactivated timestamp is taken and it should be stored on the disk. Data is only stored when lasers are "armed". They can also be in "idle" state (they're still working, but timestamps are ignored). Also, lasers can be armed/disarmed multiple times. 
What would be the most efficient way of doing this? Using plane csv/xml/txt or something else? Actual SD card that is used in RPI is limited to 8GB. 
Another question, when using open() method, should i close() the file once i executed write() method or should I keep it open as long as the script itself is running (script is running all the time until user decides to quit)?
Sounds like python?
If so, you can write to your file using with:

with open('/path', 'w') as f:
      f.write('stuff')

and the file descriptor will close automatically when execution exits the block.
However, regarding your other questions it depends on your use case. Why does it need to be available immediately? Will another process be reading it? How quickly will this be happening? Are there any other bits of data you need to save along with the timestamp - presumably whether the laser is on or off at that time?
Likely, a good solution for you would be a lightweight database such as SQLite. The storage on disk is approximately what it would be in a "flat" file, such as the .txt or .csv you reference. It will be fast. And it eliminates concern about managing the actual writing.
Persistent storage of data?