Going back to a slightly earlier version...
$newData='';
foreach($machines as $machine)
{
$newData .= str_replace($machine[0],'',$testData);
}
$file_put_contents('source-modified.txt',$newData);
While not addressing the problem you mention, I do see two other issues.
First is the most serious: you're appending a copy of the entirety of $testData (less the results of one match) to $newData each time through the loop.
Second, [man]str_replace[/man] (and [man]preg_replace[/man] can take arrays of search strings, so the loop itself only needs to collect all the strings to be replaced into a single array. The replacement can be done afterwards.