for(var/Buildings/Bed/A in world)
spawn(20)
var/obj/B=pick(A)
src.loc=locate(B.x,B.y-1,B.z)
return
Problem description: This may possibly be a BYOND bug.
For some strange reason, the player and anyone next to him/her gets teleported to the bed(B). What should be happening is just the player gets located to the bed. I've tested just setting a specific location(e.g. 1,1,1) and that works just fine. I don't know if I'm doing something wrong or if it's a BYOND bug.
Also, looping through every instance of one type of object is a very bad idea. Not to mention you're using pick() on a building/bed, pick only works on list.
simply using a list of all the beds and the world and picking from it would be easier; i.e:
That would produce the same thing.