You left the subscript ([$i]) off of the $lines reference in your ControlSend() statement.
Edit: PS - You'd run a lot faster if you just wrote your output direct to a text file via FileWriteLine(). But if having notepad.exe up and running is a requirement, you could at least use the clipboard to transfer your data as it is light-years faster than having ControlSend() process the whole string.
$var = "Line1 Error code" & @CRLF & "Line2" & @CRLF & "Line3 Error code" & @CRLF & "Line4" & @CRLF & "Line5 Error code" & @CRLF
$lines = StringSplit($var, @CRLF, 1)
$words = "Error code"
Run("Notepad.exe")
WinWaitActive("[CLASS:Notepad]")
; really slow
Sleep(1000)
For $i = 1 To Ubound( $lines ) - 1
If StringInStr($lines[$i], $words) Then
ControlSend("[CLASS:Notepad]", "", "", $lines[$i] & "{ENTER}")
EndIf
Next
ControlSend("[CLASS:Notepad]", "", "", "{ENTER}")
; slow
Sleep(1000)
For $i = 1 To Ubound( $lines ) - 1
If StringInStr($lines[$i], $words) Then
ClipPut($lines[$i] & @CRLF)
ControlSend("[CLASS:Notepad]", "", "", "^v")
EndIf
Next