Note that, contrary to what it may look like based on the size of the code, the code I gave you is far more efficient, as it uses the file handling commands (fast, minimum disk access) versus /write (slow, maximum disk access).
he is right its far more suitable also if you want to do something like write to file with the """"/LIST"""" command replace raw events with 322 and 323 , and also change links to list