If you do not currently have access to a DBI compatible database
you may want to look at using DBI and the DBD::CSV driver with your flatfiles.
It will handle your file locking (assuming you're on a system
that has flock()) and will allow you to take advantage of
the ease of use of SQL when performing your operations.
Then, when your project outgrows the use of flatfiles and
you simply have to move it to a real database, porting the
scripts should be fairly easy, since you built it around
DBI from the start.