To accomplish the request, you may use the following command:
bash sudo apt-cache policy | grep -E "Installed" | awk '{print $1}' | cut -d'/' -f2- > installed_packages.csv
Explanation :
This will list all packages and their versions on your system.
The apt-cache command provides information about the packages installed in your system.
while grep filters out unwanted output.
and awk extracts only the package names.
and cut separates each line into fields for writing to a CSV file.\