If you have the option, use a database. Someone else has already take care of the locking issues for you and as a potential bonus you get searching thrown in for no extra cost.
True laziness is hard work
Comment on Re: Trying to optimize reading/writing of large text files.