I wouldn't say there is a best practice for that...
Whatever automated method you're going to use to write to it is going to require permissions to do so. The config.php file location is not somewhere XF requires to be writable and it quite often isn't.
Generally, if you have a setting that can be controlled inside the software, the setting value should be stored inside the software - that being using the option system, session or other database storage - config.php isn't really designed or suitable for this use case.