Ahh yeah I should have posted the whole code as I forgot about the gosub.

 Code:
Break On

Color +y/b
$Tab = Chr(009)
$return =chr(13) + chr(10)
$CutoverLog = Dir("C:\Salesforce\Receive\*")
$pcclist = "C:\Salesforce\Receive\"
? "Working directory is .." + $pcclist
? "Script directory is " + @scriptdir

;
;
;
; Consolidating the Transactional data.
;
;
;

? "Month is " + @monthno
?
If @MonthNo = 1
        $Year = @YEAR - 1
Else
        $Year = @YEAR
EndIf

$Month = Right('0' + @MonthNo, 2)
? "The month is " + $month
? "The year is " + $year
?

$TransactLog = @ScriptDir + ".\Transact_FCBT_" + $Month + "_" + $Year + ".csv"


If Exist (@ScriptDir + ".\done") = 0
	MD @ScriptDir + ".\done"
EndIf

If Exist ($TransactLog) = 1
	Del $TransactLog
EndIf

$headerline = "yes"


While $CutoverLog <> "" and @Error = 0
	Open (1, $pcclist + $CutoverLog + "\" + $CutoverLog + "_Details_" + $year + $month + ".csv")
	? "Opening " + $pcclist + $CutoverLog + "\" + $CutoverLog + "_Details_" + $year + $month + ".csv"
	?
	Open (2, $TransactLog, 5)

	$Complete = False
	
	If $headerline = "no"
		$Line = Readline (1)
		$line = ""
	endIf
	
	$headerline = "no"
	
	While $Complete = False
		$Line = Readline (1)
			
			If $Line <> " " and @Error = 0
				Gosub WriteLog
			Else
				$Complete = True
			EndIf			
	Loop
	
	Close (1)
	Close (2)
	
	Del $CutoverLog
	
	$CutoverLog = Dir()
Loop

;
;
; Consolidating the Client details data
;
;
;

If @MonthNo = 1
    $Month = 12
    $Year = @YEAR - 1
	$ld = 31
Else
    $Month = @MonthNo - 1
    $Year = @YEAR
	;Create an array of Last day of each month with built-in leapyar check
	$mld = 31,28+(Not(@Year Mod 400) Or (@Year Mod 100) And Not(@Year Mod 4)),31,30,31,30,31,31,30,31,30,31
 
	;Get Last day of the current month from $mld array
	$ld = $mld[@MonthNo-2]
EndIf

$ClientLog = @ScriptDir + ".\Client_FCBT_" + $Month + "_" + $Year + ".csv"

$year = Right($year, 2)
? "The new year is " + $year
$Month = Right('0' + $Month, 2)
? "The new month is " + $month
?

? "The last date of last month is " $ld
?


If Exist ($ClientLog) = 1
	Del $ClientLog
EndIf
$CutoverLog = Dir("C:\Salesforce\Receive\*")

While $CutoverLog <> "" and @Error = 0
	Open (1, $pcclist + $CutoverLog + "\" + "Client_" + $year + $month + $ld + ".csv")
	? "Opening " + $pcclist + $CutoverLog + "\" + "Client_" + $year + $month + $ld + ".csv"
	?
	Open (2, $ClientLog, 5)

	$Complete = False
	
	If $headerline = "no"
		$Line = Readline (1)
		$line = ""
	endIf
	
	$headerline = "no"
	
	While $Complete = False
		$Line = Readline (1)
			
			If $Line <> " " and @Error = 0
				Gosub WriteLog
			Else
				$Complete = True
			EndIf			
	Loop
	
	Close (1)
	Close (2)
	
	Del $CutoverLog
	
	$CutoverLog = Dir()
Loop

copy $ClientLog @Scriptdir + "\done"
copy $TransactLog @Scriptdir + "\done"

:WriteLog
WriteLine (2, $Line + $return)


I see what you've done so that headerline would only be processed once and forgotten about for each loop afterwards.

Let me give it a go.

I know this code is not neat, but I'd taken code I was given which wasn't working for our situation and adapting it as best as I have given my limited knowledge.

Thanks for the comments so far.

Pax