It should be possible to write to disk fields with identical dimension or auxiliary coordinates to different groups, but this causes a failure at cf v3.12.0 (and earlier versions) from cf.write, which complains that the netCDF data variable dimensions are not in the same group or a parent group as the data variable itself.
It is good that cf.write complains about this, as it is a valid restriction, but it shouldn't have ended up in that situation in the first place.
The error comes from cfdm and is fully described and fixed in NCAS-CMS/cfdm#177.
To solve the problem in cf, simply upgrade to the cfdm dependency to cfdm v1.9.0.3 (due for release early March 2022).
Many thanks to @ajelenak who noticed and diagnosed this problem, and provided the minimal reproducer which can be seen at NCAS-CMS/cfdm#177.