how to make the filenames shorter in length?

Just as an extra option: if you want to make sure that you do not get too many errors that the renaming fails as there is already a file with that (shorter) name, it is ususally a good idea to take care that a number, e.g. the track number does not get trunkated.
So either you construct a filename that limits the number of characters of all the variables to a certain maximum or you subtract the 4 characters needed for the tracknumber from that length.