Creating a constant current source using an Arduino, BC548 transistor and LM317LZ Voltage Regulator
In theory it could work. However, the LM317(LZ) has internal capacitors in it's circuit. It is not ment for a PWM signal at its input.

Connecting a Arduino pin directly to the base seems dangerous. That could result in peaks of 40mA through the base and peaks of negative voltages of Vbe.

It is possible to create a current PWM, but that is often done in a different way. A chopper driver for a stepper motor uses some kind of current PWM, and some led controllers use some kind of current PWM.

Here is the same question: Is it OK to PWM a current source?. There are more links in the answers over there to more info and also a schematic.

What is it for ?