Added flockfile calls and fixed SET_FILE_BINARY usage for consistency