GroupBy is not required. Actually, there are a few issues here.
When unfamiliar, don't try and do it all at once. The best to break out the parts required, then tighten up the code.
Something like this...
foreach (var uniqueSection in xdoc.Descendants("sec"))
{
var title = uniqueSection.Element("title")?.Value;
foreach (var sectionBreak in uniqueSection.Descendants("break"))
{
var heading = sectionBreak.Element("heading")?.Value;
var bl = sectionBreak.Element("bl")?.Value;
var body = sectionBreak.Descendants("p").Select(x => x.Value);
}
}
Now, set a breakpoint and step through the code and check that the correct parts are being selected at each step.
Once you know that the code is pulling the correct parts, now you are ready to write out to the separate files.