You can refer to the sample code in the document I uploaded.
This command will also export a user name similar to SHAREPOINT\system, which is unavoidable, SHAREPOINT\system is the system automatically generated users.
In addition, you can also refer to the article below:
SharePoint Online: User Permissions Audit Report for a Site Collection using PnP PowerShell
Please note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.