I created a script that reads and writes data in an excel file, using the excel module for the following actions: count rows, read cell, write to cell. There is also another script that simultaneously reads and writes data in this xlsx file. The file has 40 rows (10 Kb)
Everything works great for 1-2 hours, but the excel file starts to grow and reaches about 400-500 Kb, though new data is not added but old data is being updated.
When this happens all the threads that are using this file are getting this error:

...and the file becomes corrupted and I cannot open it anymore
I tried switching to csv, but when trying to count all the rows, I'm getting this error:

Anybody has any idea what I'm doing wrong with this excel module?
LE: Found on the forum that switching to CSV cannot be done with the excel module. But haven't found any fix for the main problem (xlsx file growing and corrupted)