There are a number of versions of this quote and it is attributed to a number of sources such as in the story the Monkey's Paw, which is a classic horror story apparently written by W.W. Jacobs,, first appearing in Harpers Monthly in 1902. The story begins with a quotation "Be careful what you wish for, you may receive it" - unfortunately attributed by the author to Anonymous.
Then there are:
Be careful what you
set your heart upon--
for it will surely be yours.
Attributed to James Baldwin
Or
I write of the wish that comes true--
for some reason,
a terrifying concept.
By James M. Cain
Or
Ambition is a Dead Sea fruit
and the greatest peril to the soul is that
one is likely to get precisely what he is seeking. By Edward Dahlberg
Or
Beware, my Lord!
Beware lest stern Heaven hate
you enough to hear your prayers!
By Anatole France