Improved XConfig writing: Add atomicity, better error handling