You do not define what "near retirement" means in terms of your age. If you take money out of a 401k before you are 59 1/2, you pay a 10% early withdrawal penalty + ordinary income tax on the distribution. Using the money to pay for a house is not an exception to the 10% penalty for a 401k.
Any money you remove from your 401k or IRA is subject to ordinary income tax. You will get a 1099R for the distribution which you will need to enter on your income tax return. Using the money for a retirement home is irrelevant.
I am NOT one of the experts, but was in the same situation. I had a lot of equity in my current home, so I used a home equity line of credit to purchase a lower priced new home. When the current home sold, it automatically paid off the loan. There was only about 50 days of interest, I didn't have to touch my 401K, and the process was easier than a normal loan.
When you withdraw funds from a Traditional IRA/401K, you will pay taxes on it. If you are 59 1/2 years or older you would not have to pay penalty on the withdrawal. As you currently own the home you are trying to sell, you will not qualify for a new home exclusion from penalty on the first $10,000.00. This exclusion from penalty is only available once. Though taxes will be owed on the full amount withdrawn from Traditional IRA/401K.
Also remember, you may owe taxes on the sale of your existing home. The exclusion amount for capital gains tax is on first $250,000 if single filer or married filing separately or $500,000 if married filing jointly.
Here is a link to help you understand if the 10% additional tax/penalty for early withdrawal and tax on withdrawal from a retirement account will apply to you.
IRS: Exception to tax on early Withdrawal