Can both sentences be used?
I need a bed to sleep in.
I need a bed to sleep.
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 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...
TRomano put it well. Both are acceptable in my mind, although the connotation is different. You may wish to bear in mind that a lot of teachers will take exception to ending a sentence in a preposition. This is one of those arbitrary no-no's that English writing and language teachers love.
However, I would simply say "I need a bed." It will be presumed you need to sleep. Otherwise the subject would be "we" and really, you wouldn't really be obliged to tell people why the bed was needed.