I remember reading long ago that the prophet Elijah sometimes will appear to a dying man pretending to be a beggar asking charity, to give the man one last chance of doing an act of tzedakah. Is this correct and what is the reference?
Did you read a somewhat similar story which appears in Louis Ginzberg's The Legends of the Jews, vol. 4 ch. 7 ?
There were two brothers, one of them rich and miserly, the other poor and kind-hearted. Elijah, in the garb of an old beggar, approached the rich man, and asked him for alms. Repulsed by him, he turned to the poor brother, who received him kindly, and shared his meagre supper with him. On bidding farewell to him and his equally hospitable wife, Elijah said: "May God reward you! The first thing you undertake shall be blessed, and shall take no end until you yourselves cry out Enough!" Presently the poor man began to count the few pennies he had, to convince himself that they sufficed to purchase bread for his next meal. But the few became many, and he counted and counted, and still their number increased. He counted a whole day, and the following night, until he was exhausted, and had to cry out Enough! And, indeed, it was enough, for he had become a very wealthy man.
His brother was not a little astonished to see the fortunate change in his kinsman's circumstances, and when he heard how it had come about, he determined, if the opportunity should present itself again, to show his most amiable side to the old beggar with the miraculous power of blessing. He had not long to wait. A few days later he saw the old man pass by. He hastened to accost him, and, excusing himself for his unfriendliness at their former meeting, begged him to come into his house. All that the larder afforded was put before Elijah, who pretended to eat of the dainties. At his departure, he pronounced a blessing upon his hosts: "May the first thing you do have no end, until it is enough." The mistress of the house thereupon said to her husband: "That we may count gold upon gold undisturbed, let us first attend to our most urgent physical needs." So they did and they had to continue to do it until life was extinct.