“One dollar and eighty-seven cents. That was all. And sixty cents of it was in pennies. Pennies saved one and two at a time by bulldozing the grocer and the vegetable man and the butcher until one’s cheeks burned with the silent imputation of parsimony that such close dealing implied. Three times Della counted it. One dollar and eighty-seven cents. And the next day would be Christmas.” (from “The Gift of the Magi” by O. Henry)
You are correct that in general, sentence fragments are to be avoided. However, authors may choose to use them for a few different reasons. Remember that any artistic choice a writer makes is usually intentional and not accidental! Writers change their sentence structure to create certain effects.
In this example from O. Henry’s “The Gift of the Magi,” sentence fragments are used to add emphasis and create urgency.
The emphasis is being placed on the minimal amount of money that Della has available. The phrase “one dollar and eighty-seven cents” is repeated twice, adding emphasis to the story. The reader is meant to understand what a dire situation Della feels herself in.
In addition, a sense of urgency is created by the sentence fragments. The reader understands that there’s not much money to go around but THEN, we discover that it’s Christmas Eve. Della only has “one dollar and eighty-seven cents” on Christmas Eve. We do not know what she needs the cash for, but clearly she needs more of it, and quickly.