See the attached image for log when user is created.
Instead of the username I get some ID as username. This ID changes each time you log in so a new user is created at each login. I dont understand what I have done wrong, the users first name, last name and email are sent correctly to portal.
The username is set to be sent as NameID.
Yes, that is by design. See the following Portal for ArcGIS - SAML documentation:
"Since ArcGIS Enterprise uses the value of NameID to uniquely identify a named user, it is recommended that you use a constant value that uniquely identifies the user. When a user from the IDP signs in, a new user with the username NameID will be created by the ArcGIS Enterprise organization in its user store. "