Variables should always be double-quoted (except when that would change the intent).
Suggested practices for target shell should be used - if writing for bash, $() instead of backticks, etc.
If writing for sh, a minimum subset of other utility functionality should be used (for example, sed -i should not be used as it might not be supported on some Unices).
If you have to write to a file that other process might read and that might result in a race condition (where writing to the file has not been completed yet), use mv, as it must be atomic according to POSIX.
If you have to create locking in a shell script, use directories, not files. mkdir is atomic, thus mkdir lockdir should never allow two processes to lock at the same time.
Don't use cat where it is not needed. Use grep string file instead of cat file | grep string. Also see Useless use of cat.