Also re: file write limit – the write limit occurs when the file is repeatedly opened and closed in a short period of time and not strictly when the write() function is called repeatedly (that is, it occurs when the file is repeatedly written to long-term storage and not when the file is modified in RAM). The write limit can be avoided by keeping the file open while you do reading/writing and only closing it once you're completely done accessing it.