Praise be to Allah.
We put this question to Shaykh Muhammad ibn Saalih al-Uthaymeen, may Allaah preserve him, who answered as follows:
There is nothing wrong with that, unless it involves great expense. It could be said that it is a waste of money because there is no need to know the sex of the baby except for the purposes of merely feeling happy because one knows whether it is a boy or a girl. If finding out could not be achieved without spending a lot of money then it is a waste of money and is not permitted. And Allaah knows best.