Help on generating output to a CSV using PNP Powershell

I have this script to get the hub sites and associated sites. Instead of write-host, how do I  collect the results in a collection and output with for example Export-Csv.

# List all sites being a hub site or associate to a hub site
$results = Submit-PnPSearchQuery -Query 'contentclass=sts_site' -RefinementFilters 'departmentid:string("{*",linguistics=off)' -TrimDuplicates $false -SelectProperties @("Title","Path","DepartmentId","SiteId") -All -RelevantResults


# Filter out the hub sites
$hubSites = $results |? { $_.DepartmentId.Trim('{','}') -eq $_.SiteId }

# Loop over the hub sites
foreach( $hub in $hubSites ) {
Write-Host $hub.Title - $hub.Path - $hub.SiteDescription

# Filter out sites associated to the current hub
$associatedSites = ($results |? { $_.DepartmentId -eq $hub.DepartmentId -and $_.SiteId -ne $hub.SiteId })
foreach($site in $associatedSites) {
Write-Host "`t"$site.Title - $site.Path -ForegroundColor Yellow
}
}