Temazepam is used on a short-term basis to treat insomnia (difficulty falling asleep or staying asleep). Temazepam is in a class of medications called benzodiazepines. It works by slowing activity in the brain to allow sleep..