public function writeFile($filename, $contents, $backup = true)
    {
        $fs = new SymfonyFilesystem();
        if (file_exists($filename) && $backup && $contents !== file_get_contents($filename)) {
            $backupName = dirname($filename) . '/' . basename($filename) . '.bak';
            $fs->rename($filename, $backupName, true);
        }
        $fs->dumpFile($filename, $contents);
    }