Most programs are written with the assumption that only one copy will be running at any given time. Therefore, access to data files will only be made by one copy of the program. However, that is not always true of CGI programs, for which any number of copies may be running at any one time [one for each user submitting a form]. For reading of data files, where no changes are being made, this isn't a problem. But as soon as modification of the data files [through writing] is introduced, this becomes a major problem.
If one process is writing a file while the other is reading, the reading process may read only partially-written data, resulting in incomplete data. If two processes are writing at the same time, their data may be interleaved and completely unusable. This can result in corrupt and lost data.
The [somewhat] simple answer to this problem is file locking. Any process which is going to write to a data file must first obtain a lock on the file, before doing it's writing. All others must wait for the first process to finish before continuing. If the programming environment supports native file locking, use it. If not, a lock file created by writing processes before touching the files and deleted when they are done can be used. All other processes must check for the existence of this file before proceeding, and if the file exists must periodically check back to see if it's been deleted, and they can continue. However, using a lock file is not an ideal solution because a race condition [where two processes run near-simultaneously and both think that they have the lock] may develop. Native file locking is the best solution, since it usually is set up in such a way as to limit race conditions.