It is a set phrase. It's a way of expressing sympathy and not rude. It's used to express sympathy for minor difficulties.
e.g.
- I have to get up at 5am tomorrow.
- I don't envy you!
Don't use it for major problems - redundancy, bereavement, etc. It's quite jokey and not strong enough.