Note that it says almsgiving with righteousness. In other words, almsgiving in and of itself is not meritorious, but only as an expression of charity (cf. 1 Cor. 13). Then it wins God’s favor (Heb. 13:16). It is also an act of mercy.
“Blessed are the merciful: for they shall obtain mercy” (Mt. 5:7).
“For I was hungry, and you gave me to eat; I was thirsty, and you gave me to drink; I was a stranger, and you took me in: naked, and you covered me: sick, and you visited me: I was in prison, and you came to me” (Mt. 25:35-36).
When we give alms, we are loving Christ in others. We are loving our neighbor as ourselves. So it’s not just a magic work which we perform to get automatic forgiveness.
Similarly, the sacrament of Penance is not magic, either. It is Christ who forgives our sins through the ministry of the priest (Jn. 20:23), provided we are truly sorry and intend to sin no more (Jn. 8:11).
As to the “purging of sins,” note that some sins (called mortal) destroy the life of grace and charity in our souls (1 John 5:16-17), while others do not. Venial sins do not incur the eternal punishment of hell, but only temporary punishment (called temporal). Mortal sins incur both kinds of punishment. For a biblical example of temporal punishment, see 2 Sam. 12.
Giving alms, and other acts of charity, can purge the temporal punishment due to sin, including sin already forgiven. It also reduces sinful tendencies: when we are merciful and generous, it makes us less selfish. I do not think that almsgiving can purge mortal sins; for that one needs the sacrament of Penance (or perfect contrition, that is, supernatural sorrow for having offended so good a God).