The issue is that you use fcntl to get a byte-level write lock (the lowercase w) while visudo uses flock or lockf (depending on what you have) to lock the whole file (uppercase W). The lowercase u is because visudo opens the file read-write and you open it for append.