How do you know when and where it is safe to drill into a wall?
Aim for a stud or well away from the stud.  If a line goes through a stud, there should be a metal safety plate on the stud that will keep you from going any further.

Lines that go up and down the wall will frequently be attached to the stud with staples (any electrical line running vertically will be attached) so you want to avoid just missing the stud to one side or the other.  If you don't need the support of a stud, then just poking a hole in the drywall should be well short of any line that is running between studs, however, it doesn't hurt to exercise a bit of extra caution if your near the height of nearby outlets.

To help, get a stud finder that also includes detection for metal wiring and pipes.  They aren't fool proof, but when they do find something, they can be a life saver.