From: Alexander Shatalin <sashatalin03@gmail.com>

This patch improves the safety when restoring WRITES_STRICT by ensuring:
- The variable is not empty (`-n`)
- The target file is writable (`-w`)
Also improves formatting by quoting variables and following shell best practices.

Signed-off-by: Alexander Shatalin <sashatalin03@gmail.com>