I did not understand how to extract only the data section to insert the new values
First, do you understand how to interpret the output of the print_r()? It basically says that $data is a two dimensional array. It is an associative array of numerically indexed arrays. These numerically indexed arrays are the sections.
So, suppose the user submits the form using buttonA. $_POST['buttonA'] will be set. Your script also maps 'buttonA' to 'section1', 'buttonB' to 'section2' etc (this can be done in a few ways, more on this later).
As such, you know that you are to look for the section named 'section1', and then add the data (let's call this $POST['data']. This is almost trivial:
// assume $section = 'section1'
if (array_key_exists($data, $section)) {
$data[$section][] = $_POST['data'];
}
Okay, maybe you added other data to other sections as well, did your thing, etc. Now you want to write it all back. To do this, you must write the code to transform the $data array into a string that has the format of your text file, and then fwrite() it to the text file.