yes, it should work. though I haven't done it. There are several others who put an M54 engine in an M52TU car. You will have to keep 323i's MAF, throttle body, intake, exhaust manifold, wiring, and likely have to keep: engine mounts, oil pan, coils, and valve cover.
It should bolt up and run fine as is, but you may want to reflash the DME to the 2.8 M52TU tune down the road to optimize performance. I don't think you can flash it to an M54 tune because the M54 DME is looking for a drive by wire throttle body which your car won't have.
I would not do it, unless your 323i needs a new engine. You might not notice much in higher performance and the M52TU is a good engine with typically little oil consumption