I have never really had much use for a "desktop" and this is one of the reasons. I always put each "project" in its own directory, mostly to reduce clutter, but also to limit risk to some extent. Avoiding these kinds of mistakes is one reason that I almost never actually replace files in my scripts, preferring to instead write a new output file under another name or in another directory.
While we are talking about disasters, I once tried to make the boot scripts more efficient by picking out the "restart needed" bit from the return code of fsck instead of always needing a restart after checking the root filesystem. Guess what? The shell did not really support extracting a bit from the return code and, the next time fsck changed the root filesystem, startup continued instead of stopping for a restart. Fortunately, I killed the power very quickly, but a few files were destroyed. I had to rewrite /etc/fstab from memory, which led to more fun when I forgot the swap partition. Got all the way into X and managed to start gcc before actually running out of memory. Impressive for a machine with only 64MiB RAM.