Let A be a selfadjoint operator in a separable Hilbert space, K a selfadjoint Hilbert-Schmidt operator, and f ∈ C n (R). We establish that ϕ(t) = f (A + tK) − f (A) is n-times continuously differentiable on R in the Hilbert-Schmidt norm, provided either A is bounded or the derivatives f (i) , i = 1, . . . , n, are bounded. This substantially extends the results of [3] on higher order differentiability of ϕ in the Hilbert-Schmidt norm for f in a certain Wiener class. As an application of the second order S 2 -differentiability, we extend the Koplienko trace formula from the Besov class B 2 ∞1 (R) [20] to functions f for which the divided difference f [2] admits a certain Hilbert space factorization.