If they really are the exact same model, chances are good that can work. But there are two possible sources of trouble.
1. You have Windows installed on the HDD on both machines, I presume. If you replace the drive in the second machine with the HDD from the first machine, Windows might object that it is nor licensed for that machine because it recognized that it has different serial numbers in a few components. If that happens, you'd have to contact Microsoft Tech Support and see if they can help solve that.
2. It is possible that, even though the two machines appear identical, there are a few components that differ. In a "bad" case this would cause it not to boot cleanly. More likely it might boot OK, but have a few issues with device drivers. So IF it appears to boot cleanly, then immediately go into Device Manager and look for yellow triangles that flag devices with problems. If you find any, update the device drivers for those one at a time so eliminate such problems.