If you put an array in a string, it will be expanded with $OFS (or space if $OFS is $null ) between elements. You can see the same effect with
"$txt" ''+$txt
and several others. You can set $OFS="`r`n" , which will change the space with which they are connected with line break.
You can also change Get-Content at the beginning to
$txt = Get-Content file1.txt | Out-String $txt = [IO.File]::ReadAllText((Join-Path $pwd file1.txt))
source share