I need a bed to sleep in.
You're looking for lodgings or a place to spend the night.
I need a bed to sleep.
You don't sleep very well on the floor, or on a cot or sofa; you require the comfort of a bed.
I need some music to fall asleep by.
I need some music to fall asleep.
I need a pen to write with.
I need a pen to write.
P.S. Phrases following this pattern, with the preposition at the end, are parsed as noun phrases, with the infinitive-phrase complementing the noun at the head:
words to live by ... words by which to live aka words for living | living words
shoes to run in ... shoes in which to run aka shoes for running |running shoes
light to read by... light by which to read aka light for reading | reading light
So that noun-phrase becomes the direct{direct object} of "need":
I need {shoes to run in}.
I need {shoes in which to run}.
On the other hand, phrases in this pattern:
a bed to sleep
a pen to write
music to fall asleep
the to-infinitive chunk functions like a so-called "zero"-conditional clause:
I need a bed to sleep = To sleep, I need a bed. If I want to sleep...
I need a pen to write = To write, I need a pen. If I want to write...
I need music to fall asleep = To fall asleep, I need music. If I want to fall asleep...