Run Show Version with GetStream

I run the confiiguration commad of the switch Show Version/Display version with GetStream. I save result to an XLS file:

function readtelnet {
    $response = ""
    While($Stream.DataAvailable) {
      $Read = $Stream.Read($Buffer, 0, 1024)
      $response += ($Encoding.GetString($Buffer, 0, $Read))
    }
    return $response;
  }
  
function waitfor {
    param([string]$search, [int]$timeout)
    if ($timeout -eq 0) {
      $timeout = 3
    }
    $pause = 1000
    $pending = readtelnet
    $myResult = $pending
    $counter = 0
    while ($pending -notmatch $search -and $counter -le ($timeout * (1000/$pause))) {
      $counter ++
      Start-Sleep -m $pause
      $pending = readtelnet
      $myResult += $pending
    }
    return $myResult
}

$objExcel = New-Object -ComObject Excel.Application
# Resulta
$ExcelFileRE = 'IP_de_ Switches_resulta.xlsx'
$WorkBookRE = $objExcel.Workbooks.Open($ExcelFileRE)
$WorkSheetsRE = $WorkBookRE.Sheets.Item(1)
#
$y = 2
$Socet = New-Object Net.Sockets.TcpClient
$Socet.Connect("11.1.1.1",22)
$Stream = $Socet.GetStream()
$Writer = New-Object System.IO.StreamWriter($Stream)
$Buffer = New-Object System.Byte[] 1024
$Encoding = New-Object System.Text.ASCIIEncoding
#
$Result = waitfor 'Username:' 5
$Writer.writeline($Usuario)
$Writer.Flush()
#
$Result += waitfor 'Password:'
$Writer.writeline($Contrasena)
$Writer.Flush()
#
$Result = waitfor "Show version"
$Writer.writeline("$Instruccion")
$Writer.Flush()
#
$Result += waitfor 'UNFAS1_A_\$ ' 5
$Writer.Flush()
#
$WorkSheetsRE.Cells.Item($y, 10) = $Result

The script is executed for many switches. There are cases where the variable $Result contains the result of the command and I can ssee it in console, but the XSL file ha an empty value. What could be reason? Could it be encoding?