I am trying to replace certain lines in a file that doesnt match the condition and then i need to write the output to a diff file [ I actually need the output to be redirected to the same file, but i dont know how to do it] and get the below error

Code -

```
   $fileName = E:\onlinecode\afarm_2106.txt
  $FileModified = @() 
 [System.IO.StreamReader]$afarmfile = [System.IO.File]::Open("E:\onlinecode\Btnbar64\a_farm.txt", 
 [System.IO.FileMode]::Open)
while (-not $afarmfile.EndOfStream){
$line = $afarmfile.ReadLine()
     if ( $Line -like "*2104 Training Markets*" ) 
            {  
              $FileModified += $Line 
              # Write-Output $FileModified
             }
            else
            {         
             $FileModified += $Line -replace "2104","2106" -replace "21043","21062"

            }
      }
 $afarmfile.Close() 
 Set-Content -Path $filename -value $FileModified 

```

Error -

```
 Set-Content : Cannot bind argument to parameter 'Path' because it is null.
 At line:19 char:19
+ Set-Content -Path $filename -value $FileModified
+                   ~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Set-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : 
ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand

```

Any help to resolve the issue / Directly write to the same file would be appreciated