&lock_open(TXT, "a.txt");
@txt = <TXT>;
&unlock_close(TXT);

open(OUT,"> x.txt");
print OUT "@txt";
close(OUT);

&lock_open(TXT, "a2.txt");
@txt = <TXT>;
&unlock_close(TXT);

open(OUT,">> x.txt");
print OUT "@txt";
close(OUT);

&lock_open(TXT, "x.txt");
@txt = <TXT>;
&unlock_close(TXT);
foreach $m (@txt) { chop($m); }
でできました。opendirの意味がいまいちわからなかったので544さんの「それはopendirしたディレクトリのファイルリストを得る関数だ」
の助言で納得できました。おさわがせしてすみませんでした。ありがとうございます。