Your code looks fine to me, I can only speculate for reasons.
Could you try it with the -NoHeader option? This is available only after Powershell version 7.4
so pls make sure you have the version requirement.
if (-Not (Test-Path $CSVFile)) {
$logEntries | Export-Csv -Path $CSVFile -NoTypeInformation
} else {
# Append with the -NoHeader option
$logEntries | Export-Csv -Path $CSVFile -NoTypeInformation -Append -NoHeader
}