Fixed a mutex locking logic error. We're now using a global lock var between threads when writing to a file.