First, use
File::Copy to create the backup file and I'd include a timestamp as part of the filename to maintain a history.
Load your text file into a hash or a HoA (hash of arrays) or a HoH (hash of hashes) where the keys are the hostnames and the values are the licenses. This will make it very easy to separate the assigned and unassigned licenses. Then take one of the unassigned licenses and move it to the assigned group. Then sort the hash and output its data to the file.
Your substitution regex is using $ENV{'ComputerName'} and implies that the script will be run on the laptop instead of the deployment server, which doesn't make sense. Where is the laptop hostname coming from?