A baptized infant or young child can go to Heaven without any good works. But a baptized adult must remain in a state of grace until death — or at least return to that state before he dies — in order to be saved. Baptism, and the grace of justification it provides, is a free unmerited gift from Jesus Christ. But to retain that gift, we must avoid all actual mortal sins, those of commission and those of omission.
How does this pertain to the question of good works? It is a mortal sin of omission for an adult in a state of grace, who has the ability, to refuse to help his neighbor in need, whether it is a spiritual need or a temporal need. The positive precept to love your neighbor as yourself requires you to do good works for your neighbor. A person in a state of grace is on the path to Heaven. But he departs from that path by refusing to help his neighbor in need.
The positive precepts allow for some discretion, as to how and when you will help your neighbor in need. But to turn away entirely from that need, in order to live an entirely selfish life, is a grave sin. Therefore, there is a sense in which good works are important, even at times essential, to the path of salvation.
For the good works of someone in a state of grace are, in one sense, the gifts of God. But these same works are also, in another sense, the good merits of the person in a state of grace. Such a person, by the good works he or she performs through the grace of God and the merits of Jesus Christ, truly merits an increase in grace, eternal life, and the attainment of that eternal life — if he dies in a state of grace — and also an increase in glory.
So good works are necessary to avoid the actual mortal sin of omission of refusing to love our neighbor in need. And good works are important to increase grace and to merit eternal life and eternal glory. However, our true merit of eternal life is predicated on the prior good work of Christ, who first merits all grace and eternal life for us. Without Christ, we would merit nothing. So our merits are secondary, and His are primary.