Watch Out for Data Loss When Redirecting to a File in a Shell Script

There's a number of subtle things going on when you redirect output to a file, here's how to do it safely and verify it with strace.