It comes with experience
The experience really helps mainly because you know what the message is likely to be! If you already know what the message is likely to be, then you only really need to additionally remember the bits taht weren't as expected!
Except when in critical phases of flight such as take off / landing /circuit you should always write down any instructions or clearances you get, and then read back what you have written down...not what you remember!
Otherwise there is the possibility that you'll write down something incorrect, but make a correct readback. In that case the controller thinks you know what you are doing, but when you check the clearance that you wrote down you'll actually follow something different!