Thanks for posting your question,
You are on the right track, with the current line of powershell you have there you are getting data from Graph to match with the serial number you have in your variable.
The next step would be to update the information to set a new management name on the device and it can be done with the following example:
Update-IntuneManagedDevice -managedDeviceId $device.id -managedDeviceName "New management device name"
hope this helps.