You can certainly use file locking for this purpose, but bear in mind that you can't lock a file which doesn't exist.
Also, locking semantics differ between operating systems; Unix locks aren't mandatory so they don't stop another process from messing the file up, they just stop it from taking its own lock. They do nothing against a file being deleted.
Depending on how often you're having this problem, you could use a separate lock file, or lock the files themselves. If you do the latter, you probably need to open them read/write if you intend to write to them, and then acquire a write lock before you truncate the file. Or something.
Mark