Since I don't know how mdadm.conf looks like I can't be sure, but while this looks pretty safe, maybe you could regenerate this as a template each time there's a change. That way there's no need to reason about whether it's getting appended properly or not. Depending on the format this might not be worth it, just a thought.