<?php $filename = 'D:\\Testfolder\\Тест.txt';
$cont = file_get_contents($filename);
$enc = mb_detect_encoding($cont, 'UTF-8', true);
$text = iconv($enc,'UTF-8',$cont);
var_dump($text);
$text .= '
Ба';
file_put_contents($filename, $text);
<?php $filename = 'D:\\Testfolder\\Тест.txt';
$cont = file_get_contents($filename);
$enc = mb_detect_encoding($cont, 'UTF-8', true);
$text = iconv($enc,'UTF-8',$cont);
var_dump("\nbefore save: "$text);
$text .= '
Ба';
file_put_contents($filename, $text);
var_dump("\nafter save: "$text);